package com.ebupt.migu.music.autotri.service.impl;

import com.ebupt.migu.music.autotri.entity.push.PushBean;
import com.ebupt.migu.music.autotri.service.MoreTemService;
import com.ebupt.migu.music.commons.utils.JsonUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author tz
 */
@Service
public class MoreTemServiceImpl implements MoreTemService {

    @Override
    public Map<String, Object> randomTem(Map<String, Object> param) {
        //处理结果集
        Map<String,Object> reMap = JsonUtils.beanToMap(new PushBean());
        //获取随机数，数组长度下标
        int rand = (int)(0+Math.random()*Integer.parseInt(param.get("templateNum").toString()));
        //遍历结果集，给对应key随机赋值
        reMap.replaceAll((k, v) ->
                param.get(k).toString().replaceAll("\n\\^","\\^")
                        .split("\\^")[rand]);
        return reMap;
    }

}
